package sjg.DataStructures.recursion;

public class RecursionTest {
    public static void main(String[] args) {
//        test(4);
        int n = 4;
        int factorial = factorial(n);
        System.out.printf("%s 的阶乘 = %s", n, factorial);
    }


    /**
     * 阶乘问题
     *
     * @param n 求n的阶乘
     */
    public static int factorial(int n) {
        if (n == 1) {
            return 1;
        } else {
            System.out.printf("（%s-1)*%s", n, n);
            System.out.println();
            return factorial(n - 1) * n;
        }
    }


    public static void test(int n) {
        if (n > 2) {
            test(n - 1);
        }
        System.out.println("n=" + n);
    }
}
